<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Utils\QueryUtil;


class CreatTableTestResAll extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('test_reports', function (Blueprint $table) {
            $table->id();
            $table->char('test_report_uid', 32)->default('')->comment('测试报告唯一UUID');
            $table->string('title',1024)->default('')->comment('测试单子标题');
            $table->integer('test_api_sun')->default(0)->comment('总共测试接口总数');
            $table->integer('test_param_sun')->default(0)->comment('总共测试参数(用例)总数');
            $table->integer('success_param_sun')->default(0)->comment('成功参数(用例)总数');
            $table->integer('duration')->default(0)->comment('单位毫秒');
            $table->string('test_adminer', 128)->default('')->comment('执行测试人');
            $table->timestamp('tested_at')->nullable()->comment('测试时间');
            $table->string('created_adminer', 128)->default('')->comment('测试单创建人');
            $table->text('remark')->nullable()->comment('测试单说明');
            $table->text('explain')->nullable()->comment('记录测试的项目，产品，主模块，子模块');
            $table->tinyInteger('status')->default(0)->comment('状态 0待测试 1已测试');

            $table->timestamps();
            $table->index('test_report_uid');
            $table->index('test_adminer');
        }); QueryUtil::tableComment('test_reports', '测试报告单子表');

        Schema::create('test_modules', function (Blueprint $table) {
            $table->id();
            $table->char('test_report_uid', 32)->default('')->comment('测试报告唯一UUID');
            $table->string('cate_name',128)->default('')->comment('测试项目组');
            $table->string('project_name',128)->default('')->comment('测试项目');
            $table->string('product_name',128)->default('')->comment('测试项目');
            $table->string('f_module_name',128)->default('')->comment('测试主模块');
            $table->string('s_module_name',128)->default('')->comment('测试子模块');
            $table->integer('s_module_id')->default(0)->comment('原始子模块id');
            $table->integer('test_api_sun')->default(0)->comment('总共测试接口总数');
            $table->integer('test_param_sun')->default(0)->comment('总共测试参数(用例)总数');
            $table->integer('success_param_sun')->default(0)->comment('成功参数(用例)总数');
            $table->tinyInteger('status')->default(0)->comment('状态 0待测试 1已测试');

            $table->timestamps();
            $table->index('test_report_uid');
        }); QueryUtil::tableComment('test_modules', '测试模块表');

        Schema::create('test_apis', function (Blueprint $table) {
            $table->id();
            $table->char('test_report_uid', 32)->default('')->comment('测试报告唯一UUID');
            $table->integer('test_module_id')->default(0)->comment('测试模块ID');
            $table->integer('api_id')->default(0)->comment('接口名称');
            $table->string('api_name', 128)->default('')->comment('接口名称');
            $table->string('api', 128)->default('')->comment('原始APi');
            $table->string('path', 128)->default('')->comment('APi路径');
            $table->string('domain', 128)->default('')->comment('域名');
            $table->json('headers')->nullable()->comment('执行header头值');
            $table->string('method_type', 16)->default('')->comment('POST GET');
            $table->integer('test_param_sun')->default(0)->comment('总共测试参数(用例)总数');
            $table->integer('success_param_sun')->default(0)->comment('成功参数(用例)总数');
            $table->tinyInteger('status')->default(0)->comment('状态 0待测试 1通过 2不通过');

            $table->timestamps();
            $table->index('test_report_uid');
            $table->index('test_module_id');
            $table->index('api_id');
            $table->index('status');
        }); QueryUtil::tableComment('test_apis', '测试接口表');

        Schema::create('test_param_res', function (Blueprint $table) {
            $table->id();
            $table->char('test_report_uid', 32)->default('')->comment('测试报告唯一UUID');
            $table->integer('test_module_id')->default(0)->comment('测试模块ID');
            $table->integer('test_api_id')->default(0)->comment('测试接口ID');
            $table->integer('api_id')->default(0)->comment('原始接口ID');
            $table->integer('param_id')->default(0)->comment('原始参数(用例)ID');
            $table->json('param')->nullable()->comment('执行参数值');
            $table->json('res')->nullable()->comment('测试返回结果');
            $table->string('http_code', 16)->default('200')->comment('结果返回Http状态码');
            $table->integer('duration')->default(0)->comment('单位毫秒');
            $table->integer('test_validator_sum')->default(0)->comment('check验证器总数');
            $table->integer('success_validator_sum')->default(0)->comment('通过check验证器数');
            $table->tinyInteger('status')->default(0)->comment('状态 0待测试 1接口参数请求错误 2请求成功验证器未通过 3请求成功验证器也通过');
            $table->timestamps();

            $table->index('test_report_uid');
            $table->index('test_module_id');
            $table->index('test_api_id');
            $table->index('api_id');
            $table->index('param_id');
            $table->index('status');
        }); QueryUtil::tableComment('test_param_res', '测试用例结果表');

        Schema::create('test_validator_res', function (Blueprint $table) {
            $table->id();
            $table->char('test_report_uid', 32)->default('')->comment('测试报告唯一UUID');
            $table->integer('test_module_id')->default(0)->comment('测试模块ID');
            $table->integer('test_api_id')->default(0)->comment('测试接口ID');
            $table->integer('api_id')->default(0)->comment('原始接口ID');
            $table->integer('param_id')->default(0)->comment('原始参数(用例)ID');
            $table->integer('validator_id')->default(0)->comment('原始验证器ID');
            $table->integer('param_res_id')->default(0)->comment('测试参数ID');

            $table->string('rule', 128)->default('')->comment('取样验证规则 $.code');
            $table->string('expect_value', 225)->comment('')->comment('期望值');
            $table->text('true_value')->nullable()->comment('验证器取到的值');
            $table->tinyInteger('status')->default(0)->comment('状态 0未验证 1接口参数请求错误 2请求成功未取到验证字段 3请求成功取到验证字段验证不通过 4请求成功取到验证字段验证通过');
            $table->timestamps();

            $table->index('test_report_uid');
            $table->index('test_module_id');
            $table->index('test_api_id');
            $table->index('api_id');
            $table->index('param_id');
            $table->index('validator_id');
            $table->index('status');
        }); QueryUtil::tableComment('test_validator_res', '测试验证器结果表');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
